package com.tencent.tws.watchfacelib.manager;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.tencent.tws.api.healthkit.Health;
import com.tencent.tws.api.healthkit.HealthKitResponse;
import com.tencent.tws.api.healthkit.IHealthKitService;
import com.tencent.tws.api.healthkit.IHealthKitService.Stub;
import com.tencent.tws.api.healthkit.RequestHealthResult;
import com.tencent.tws.watchfacelib.ServiceConnectionManager;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

public class HealthKitServiceManager
{
  private static final int DEF_GOAL_STEP = 10000;
  private static final int PEDOMETER_TODAY = 0;
  private static final String TAG = HealthKitServiceManager.class.getSimpleName();
  private Context mContext;
  private final ServiceConnectionManager mHealthKitServiceConncetion;
  private IHealthKitService mIHealthKitService;
  
  public HealthKitServiceManager(Context paramContext)
  {
    this.mContext = paramContext;
    this.mHealthKitServiceConncetion = new ServiceConnectionManager(paramContext)
    {
      public void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
      {
        super.onServiceConnected(paramAnonymousComponentName, paramAnonymousIBinder);
        Log.v(HealthKitServiceManager.TAG, "Pedometer and HealthKit onServiceConnected.");
        HealthKitServiceManager.this.mIHealthKitService = IHealthKitService.Stub.asInterface(paramAnonymousIBinder);
        HealthKitServiceManager.this.requestTodayStep();
        HealthKitServiceManager.this.getGoalStep();
      }
      
      public void onServiceDisconnected(ComponentName paramAnonymousComponentName)
      {
        super.onServiceDisconnected(paramAnonymousComponentName);
      }
    };
  }
  
  public static int ParseHealthKitResponseStep(HealthKitResponse paramHealthKitResponse)
  {
    if (paramHealthKitResponse.resultType == 0)
    {
//      paramHealthKitResponse = (Health)paramHealthKitResponse.getData().get(0);
//      if ((paramHealthKitResponse != null) && (paramHealthKitResponse.healthType == 19)) {
//        return paramHealthKitResponse.value;
//      }
//      Log.i(TAG, "health data null or type not step counter");
      return 0;
    }
    if (paramHealthKitResponse.resultType == 1)
    {
      Log.i(TAG, "step empty");
      return 0;
    }
    Log.e(TAG, "content type unknown:" + paramHealthKitResponse.resultType);
    return 0;
  }
  
  public boolean bindService()
  {
    if (this.mHealthKitServiceConncetion == null)
    {
      Log.e(TAG, "bindService, mHealthKitServiceConnection is null");
      return false;
    }
    Intent localIntent = new Intent();
    localIntent.setAction("com.tencent.tws.watchside.healthkit.HealthKitService");
    localIntent.setPackage("com.tencent.tws.watchside");
    return this.mHealthKitServiceConncetion.bindService(localIntent, 1);
  }
  
  public int getGoalStep()
  {
    int i = 10000;
    int j = i;
    int k = i;
    int m = i;
    int n = i;
    int i1 = i;
    try
    {
      Class localClass = Class.forName("com.tencent.tws.launcher.utils.PedometerManager");
      j = i;
      k = i;
      m = i;
      n = i;
      i1 = i;
      Object localObject = localClass.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
      j = i;
      k = i;
      m = i;
      n = i;
      i1 = i;
      i = ((Integer)localClass.getMethod("getGoalPedometer", new Class[0]).invoke(localObject, new Object[0])).intValue();
      j = i;
      k = i;
      m = i;
      n = i;
      i1 = i;
      Log.d(TAG, "goalStep:" + i);
      return i;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      localClassNotFoundException.printStackTrace();
      return j;
    }
    catch (NoSuchMethodException localNoSuchMethodException)
    {
      localNoSuchMethodException.printStackTrace();
      return k;
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      localIllegalArgumentException.printStackTrace();
      return m;
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      localIllegalAccessException.printStackTrace();
      return n;
    }
    catch (InvocationTargetException localInvocationTargetException)
    {
      localInvocationTargetException.printStackTrace();
    }
    return i1;
  }
  
  public RequestHealthResult requestTodayStep()
  {
    if (this.mIHealthKitService == null)
    {
      Log.w(TAG, "mIHealthKitService is NULL");
      return null;
    }
    try
    {
      RequestHealthResult localRequestHealthResult = this.mIHealthKitService.getPedometerPeriod(this.mContext.getPackageName(), 0);
      return localRequestHealthResult;
    }
    catch (RemoteException localRemoteException)
    {
      localRemoteException.printStackTrace();
    }
    return null;
  }
  
  public void unbindService()
  {
    this.mHealthKitServiceConncetion.unbindService();
  }
}


/* Location:              G:\zyl\ylwork\Android\Android_Decode\apk2java\apktool2.1.0\WatchFaceSports\classes-dex2jar.jar!\com\tencent\tws\watchfacelib\manager\HealthKitServiceManager.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */